import { FC, useReducer } from 'react'

/**
 * 数据
 * const reducer
 * 
 * useReducer
 * useReducer(reducer, initialState),
 * 类似redux里的 createStore(reducer, composeWithDevTools())
 * 
 * 点击函数
 * const addcount = () => dispatch({ type: 'add' })
 */
const reducer = (state: any, action: any) => {
	if (action.type === 'add') {
		return {
			...state,
			count: state.count + 1,
		}
	} else {
		return state
	}
}

const Foo: FC = () => {
	const [state, dispatch] = useReducer(reducer, { count: 0 })
	const addcount = () => dispatch({ type: 'add' })

	return (
		<>
			<button onClick={addcount}>countA++ =&gt; {state.count}</button>
		</>
	)
}
export default Foo
